package cn.sinata.wanglin.net;
import cn.sinata.wanglin.json.JsonConverterFactory;
import cn.sinata.wanglin.json.JsonConverterFactoryNoDes;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
/**
 *
 * Created by liaoxiang on 16/6/20.
 */
public class RRetrofit {
    private static volatile RRetrofit INSTANCE;
    private static Retrofit retrofit;
    private static Retrofit retrofitOther;
    private RRetrofit(){
        Retrofit.Builder builder = new Retrofit.Builder();
        retrofit = builder
                .baseUrl(API.BASE_URL)//注意此处,设置服务器的地址
                .addConverterFactory(JsonConverterFactory.create())//用于Json数据的转换,非必须
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())//用于返回Rxjava调用,非必须
                .build();
    }
    public RRetrofit(String url){
        Retrofit.Builder builder = new Retrofit.Builder();
        retrofitOther = builder
                .baseUrl(url)//注意此处,设置服务器的地址
                .addConverterFactory(JsonConverterFactoryNoDes.create())//用于Json数据的转换,非必须
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())//用于返回Rxjava调用,非必须
                .build();
    }

    public static RRetrofit getInstance(){
        if (INSTANCE==null){
            synchronized (Retrofit.class){
                if (INSTANCE == null){
                    INSTANCE = new RRetrofit();
                }
            }
        }
        return INSTANCE;
    }

    public <T> T create(final Class<T> cls) {
        return retrofit.create(cls);
    }
    public <T> T createOther(final Class<T> cls) {
        return retrofitOther.create(cls);
    }
}
